import {createStore, compose, combineReducers} from 'redux';
// import thunk from 'redux-thunk';
import countReducer from "./modules/count";
import homeReducer from './modules/home';
import {log, thunk, applyMiddleware} from './middleware'

const combinedReducers = combineReducers({count: countReducer, home: homeReducer})
// composeEnhancers是个组合函数
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({trace: true}) || compose;

// combinedReducers实现原理
const myCombinedReducers = (store = {}, action) => {

    // 返回一个对象，store的state
    return {
        count: countReducer(store.count, action),
        home: homeReducer(store.home, action)
    }
}
// thunk--中间件
// applyMiddleware--应用中间件
const store = createStore(myCombinedReducers);// 开启redux-devtools
applyMiddleware(store, log, thunk)
export default store;